package com.example.demo;

import cn.hutool.core.map.MapUtil;
import cn.hutool.extra.servlet.ServletUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * @author Administrator
 * @version 1.0
 * @description //TODO
 * @date 2024/1/15 13:27
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("/auth")
    public String printParams(Boolean flag, String rd, HttpServletRequest request, HttpServletResponse response) {
        System.out.println("测试结构进入； At: " + LocalDateTime.now());

        Map<String, String[]> pas = ServletUtil.getParams(request);
        System.out.println("rd: " + rd);
        System.out.println("params: " + request.getQueryString());

        Map<String, String> headerMap = ServletUtil.getHeaderMap(request);
        System.out.println("header params: " + headerMap.toString());

        if (flag) {
            response.setStatus(200);
        } else {
            response.setStatus(401);
        }
        System.out.println("test auth request success");

        return "redirect:" + rd;
    }
}
